//
// Created by 吴喆 on 2020/3/6.
//

#include "DemoScene.h"
#include "DemoMonster.h"
#include "../engine/SMLabel.h"

DemoScene::DemoScene() : Scene(),ratio(ConfigUtil::getPropD(ConfigConst::SCREEN_WIDTH) / ConfigUtil::getPropD(ConfigConst::SCREEN_HEIGHT)) {
    Scene::init();
}

void DemoScene::update() {
    Scene::update();
}

void DemoScene::renderBackground(Renderer &renderer) {
    renderer.DrawSprite(nullptr, Scene::currentFrame, glm::vec2(0, 0),
                        glm::vec2(ratio * 10, 10), 0.0f);
}

void DemoScene::initBackground() {
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0000.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0001.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0002.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0003.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0004.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0005.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0006.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0007.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0008.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0009.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0010.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0011.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0012.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0013.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0014.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0015.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0016.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0017.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0018.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0019.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0020.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0021.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0022.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0023.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0024.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0025.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0026.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0027.png"));
    backgroundAnimation.addFrame(ResourceManager::getTexture("background.backgroundx0028.png"));
    backgroundAnimation.setInterval(100);
}

void DemoScene::initPlayer() {
    player = new DemoPlayer(this);
    auto *demoMonster = new DemoMonster(this);
    auto *label = new SMLabel(this, glm::vec2(0, 0), 1.0, L"中文喆abcdefghijklmnopqrst");

    gameObjects.emplace_back(demoMonster);
    gameObjects.emplace_back(label);
}

void DemoScene::initMap() {
    Scene::initMap();
    map = new Map(this, world);
    map->loadMap(ConfigUtil::getProp(ConfigConst::MAP_PATH).append("test.map").c_str());
}

void DemoScene::initCamera() {
    Scene::initCamera();
}

void DemoScene::initRenderer() {
    Scene::spriteRenderer = new SpriteRenderer(ResourceManager::getShader("test"));
    Scene::backgroundRenderer = new BackgroundRenderer(ResourceManager::getShader("test"));
}

